package cn.peach.hrm.feign.client;

import cn.peach.hrm.domain.Login;
import cn.peach.hrm.dto.LoginMealDto;
import cn.peach.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LoginFeignClientFallbackFactory implements FallbackFactory<LoginFeignClient> {
    @Override
    public LoginFeignClient create(Throwable throwable) {
        return new LoginFeignClient() {
            // 降级方法
            @Override
            public AjaxResult save(Login login) {
                log.error("保存Login到认证中心异常：{}",throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("保存Login到认证中心异常");
            }

            @Override
            public AjaxResult saveLoginAndMeal(LoginMealDto loginMealDto) {
                log.error("保存Login到认证中心异常：{}",throwable.getMessage());
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("保存Login到认证中心异常");
            }
        };
    }
}
